Thumb

Create, Delete and rename table in SQL server database

9/12/2020 12:49:05 AM

In this tutorial, we will learn what is table? How to Create, Delete and rename database table in SQL server database?

Database Table:

A table is a collection of related data. It consists of columns, and rows. Each column in a database table is called a “field” and each row in a database table is called a “Record”

 Example: suppose we want create a table name is “User” and some field name is “UserId”,“UserName”,”UserMobileNo”,”UserEmail”,”UserAddress” etc. now how create this table in SQL Server let’s see.

UserId

UserName

UserMobileNo

UserEmail

UserAddress

1

Mohammad

017*******

m@gmail.com

Saudi Arabia

there are two way to create, rename & delete table in SQL server database, one is using SQL Query or Statement & other way is SQL server management studio.

Create, Rename & Delete database using SQL query:

For creating a new database table minimal syntax is

create table "tablename" 

("column1" "data type", 

"column2" "data type", 

"column3" "data type", 

... 

"columnN" "data type"); 

Example:

Use abctutorial /*Use Your_database_name*/
CREATE TABLE Users(
UserId Int IDENTITY(1,1) Primary Key,  
UserName nvarchar(80),
UserEmail nvarchar(50),
UserMobileNo nvarchar(15),
UserAddress nvarchar(255)
);  
For Rename a database table minimal syntax is
EXEC sp_rename 'old_table_name', 'new_table_name' 
Example:
Use abctutorial /*Use Your_database_name*/
EXEC sp_rename 'Users', 'New_User'

For Delete a database table minimal syntax is

DROP TABLE "table_name";

Example:

Use abctutorial /*Use Your_database_name*/
DROP Table Users

Create, Rename & Delete database table using SQL server management studio:

Create table: Right click on the database tables then select “table” after click table automatic open new window now write you table field with datatype and select primary key as like below then press “Ctrl” + “S” after press it, automatic open a new window now write your table name and click ok.

“Rename and Delete table”: Right click on your database table that you want to delete, then click "delete" and for rename click "rename"